package com.swak.boot.config.dubbo.event;

import java.util.List;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.spring.context.event.ServiceBeanExportedEvent;
import org.springframework.context.ApplicationListener;

import com.swak.annotation.Server;
import com.swak.reactivex.context.EndPoints;
import com.swak.reactivex.context.EndPoints.EndPoint;

/**
 * Dubbo 服務Bean 发布事件
 * 
 * @author DELL
 */
public class ServiceBeanExportedListener implements ApplicationListener<ServiceBeanExportedEvent> {

	@Override
	public void onApplicationEvent(ServiceBeanExportedEvent event) {
		List<URL> urls = event.getServiceBean().toUrls();
		for (URL url : urls) {
			EndPoint endPoint = new EndPoint();
			endPoint.setHost(url.getIp());
			endPoint.setPort(url.getPort());
			endPoint.setScheme(Server.Dubbo);
			EndPoints.me().setEndPoint(endPoint);
		}
	}
}
